<?php

namespace Admin\Controller;


class VoteController extends BaseController
{
    /**
     * @desc
     * @author Egor<http://gitee.com/seosite>
     */
    public function index()
    {
        $miner = M('vote');
        $count = $miner->count();
        $page = new \Think\Page($count, 10);
        $show = $page->show();
        $list1 = $miner->limit($page->firstRow . ',' . $page->listRows)->order("id DESC")->select();

        if(!empty($list1)){
            foreach($list1 as $k=>$v){
                $list1[$k]['create_time'] = date('Y-m-d H:i:s',$v['create_time']);
                $select = unserialize($v['select']);
                $temp = [];
                foreach ($select as $k2=>$v2){
                    $temp[$k2]['name'] = $v2;
                    $temp[$k2]['count'] = M('poll')->where(['vote_id'=>$v['id'],'select'=>$k2])->count();
                }
                $list1[$k]['select'] = $temp;
                $list1[$k]['getPs'] = M('poll')->where(['vote_id'=>$v['id']])->count();
            }
        }

        $this->assign('list', $list1);
        $this->assign('show', $show);
        $this->display();
    }

    public function edit()
	{
		$id= I('id');
		$info = M('vote')->find($id);

		$this->assign('info',$info);

		$poll_num = M('poll')->where(['vote_id'=>$info['id']])->count();

		$info['poll_num'] = $poll_num;

		$this->display();
	}
    public function disable()
    {
        $id = I('id');
        M('vote')->where("id = $id")->setField('is_show',2);
        $this->success("下架成功");
    }

    public function endisable()
    {
        $id = I('id');
        M('vote')->where("id = $id")->setField('is_show',1);
        $this->success("上架成功");
    }

	public function passSh()
	{
		$id = I('id');
		M('vote')->where("id = $id")->setField('status',1);
		$this->success("通过审核");
	}

	public function denySh()
	{
		$id = I('id');
		M('vote')->where("id = $id")->setField('status',3);
		$this->success("拒绝审核成功");
	}



    public function del()
    {
        $id = I('id');
        M('vote')->where("id = $id")->delete();
        $this->success("删除商品成功");
    }
}


?>